package com.gvsoft.thread;

import com.gvsoft.Client;
import com.gvsoft.GVClientMThread;
import com.gvsoft.log.Logs;

/**
 * Created with IntelliJ IDEA.
 * ProjectName:gvMsgClient
 * Author: zhaoqiubo
 * Date: 15/8/8
 * Time: 下午5:59
 * Desc: 断线重连线程：一种是正常断线，服务端会给出事件；另一种异常断线，需要维持链路线程给出标记；
 */
public class ReconnectThread extends Thread {
    public void run(){
        Logs.info("【ReconnectThread】","启动断线重连监听线程……");
        while (true){
            if(!Client.IS_CONNECT){
                Logs.info("【ReconnectThread】", "服务器通道已被中断，正在启动重连……");
                Client.connectServer();
//                (new GVClientMThread()).start();
                ThreadGroup tg = Thread.currentThread( ).getThreadGroup();
                Logs.info("【ReconnectThread】","当前活跃线程数量：【"+tg.activeCount()+"】");
                //new Thread(new GVClientMThread()).start();
//                for (int j = 0; j < 50; j++) {
//                    if(isConnect){break;}
//                    Logs.info("服务器通道已被中断，正在启动重连……");
//                    try {
//                        Thread.sleep(5000);
//                    } catch (InterruptedException e) {
//                        e.printStackTrace();
//                    }
//                    Client.connectServer();
//                }
            }
            try {
                Thread.sleep(Client.getReconnectCycle()*1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
